package com.wwinsoft.framework.pojo.common;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;

/**
 * @author: Tim Chen
 * @since 1.0
 */
@JsonIgnoreProperties(value = { "hasParent" })
public class MenuTree {

    public MenuTree() {
    }

    public MenuTree(MenuTreeNode treeNode) {
        data = treeNode.getNodeName();
        attr.put("id", treeNode.getId());
        attr.put("rel", treeNode.getNodeType());
        if (treeNode.getAttrMap() != null) {
            attr.putAll(treeNode.getAttrMap());
        }
    }

    private String data;
    private Collection<MenuTree> children;
    private String state = "open";
    private boolean hasParent = false;
    Map<String, Object> attr = new LinkedHashMap<String, Object>();

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public Collection<MenuTree> getChildren() {
        return children;
    }

    public void setChildren(Collection<MenuTree> children) {
        this.children = children;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public Map getAttr() {
        return attr;
    }

    public void setAttr(Map attr) {
        this.attr = attr;
    }

    public void addAttr(String key, Object value) {
        attr.put(key, value);
    }

    public void addChild(MenuTree menuTree) {
        if (children == null) {
            children = new ArrayList<MenuTree>();
        }
        children.add(menuTree);
    }

    public boolean isHasParent() {
        return hasParent;
    }

    public void setHasParent(boolean hasParent) {
        this.hasParent = hasParent;
    }
}
